//
//  MyProfitView.swift
//  LeGou
//
//  Created by lxm on 2022/7/29.
//

import UIKit

class MyProfitView: UIView {

    //MARK: --------------------属性--------------------
    
    //MARK: --------------------UI控件--------------------
    let title = ZMUtil.label(title: "我的收益", color: UIColor.zm.color333333(), font: UIFont.systemFont(ofSize: 16, weight: .medium))
    
    let titleSub = ZMUtil.label(title: "每月25号及以后可以提现", color: UIColor.zm.color999999(), font: UIFont.systemFont(ofSize: 12, weight: .regular))
    
    let rightIcon = ZMUtil.imageView(imageName: "mine_right")
    
    let yue = ZMUtil.label(title: "余额（元）", color: UIColor.zm.color333333(), font: UIFont.systemFont(ofSize: 12, weight: .medium))
    
    let money = ZMUtil.label(title: "10282.87", color: UIColor.zm.color333333(), font: UIFont.systemFont(ofSize: 24, weight: .bold))
    
    let withDrawButton = ZMUtil.button(title: "立即提现", image: nil, font: UIFont.systemFont(ofSize: 14, weight: .semibold), color: .white)
    
    let one = ItemView()
    let two = ItemView()
    let three = ItemView()

    
    // 分割线
    let line = UIView().then { v in
        v.backgroundColor = Style.lineColor
    }
    
    var bottomStack = ZMUtil.stackView(axis: .horizontal)
    //MARK: --------------------生命周期--------------------
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
        bindAction()
        addConstraints()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
        bindAction()
        addConstraints()
    }

    //MARK: --------------------UI--------------------
    func setUI() {
        addSubview(title)
        addSubview(titleSub)
        titleSub.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
        addSubview(rightIcon)
        addSubview(yue)
        addSubview(money)
        
        addSubview(withDrawButton)
        withDrawButton.backgroundColor = "#DE3F26".zm.hex()
        withDrawButton.layer.cornerRadius = 16
        
        addSubview(line)
        
        bottomStack.distribution = .fillEqually
        
        one.topTilte.text = "累计收益"
        one.subTitle.text = "10282.87"
        
        two.topTilte.text = "今日成交预估收益"
        two.subTitle.text = "10282.87"
        
        three.topTilte.text = "本月成交预估收益"
        three.subTitle.text = "10282.87"
        
        bottomStack.addArrangedSubview(one)
        bottomStack.addArrangedSubview(two)
        bottomStack.addArrangedSubview(three)
        addSubview(bottomStack)
    }
    
    func addConstraints() {
        title.snp.makeConstraints { make in
            make.top.left.equalToSuperview().offset(12)
        }
        
        titleSub.snp.makeConstraints { make in
            make.left.greaterThanOrEqualTo(title.snp.right).offset(8)
            make.centerY.equalTo(title)
            make.right.equalTo(rightIcon.snp.left).offset(-12)
        }
        
        rightIcon.snp.makeConstraints { make in
            make.right.equalTo(self).offset(-13)
            make.centerY.equalTo(title)
//            make.width.equalTo(17)
            
        }
        
        yue.snp.makeConstraints { make in
            make.top.equalTo(title.snp.bottom).offset(12)
            make.left.equalTo(self).offset(12)
        }
        
        money.snp.makeConstraints { make in
            make.top.equalTo(yue.snp.bottom).offset(2)
            make.left.equalTo(self).offset(12)
        }
        
        withDrawButton.snp.makeConstraints { make in
            make.centerY.equalTo(money)
            make.right.equalTo(self).offset(-16)
            make.width.equalTo(104)
            make.height.equalTo(32)
        }
        
        line.snp.makeConstraints { make in
            make.top.equalTo(withDrawButton.snp.bottom).offset(14)
            make.left.right.equalToSuperview()
            make.height.equalTo(0.5)
        }
        
        bottomStack.snp.makeConstraints { make in
            make.top.equalTo(line.snp.bottom).offset(12)
            make.left.equalTo(self).offset(12)
            make.bottom.equalTo(self).offset(-12)
            make.right.equalTo(self).offset(-12)
        }
    }
    
    //MARK: --------------------methods--------------------
    func bindAction() {
        
    }
    //MARK: --------------------delegate--------------------

}


extension MyProfitView {
    class ItemView : UIView {
        let topTilte = ZMUtil.label(title: "累计收益", color: UIColor.zm.color999999(), font: UIFont.systemFont(ofSize: 12, weight: .regular))
        
        let subTitle = ZMUtil.label(title: "10282.87", color: UIColor.zm.color333333(), font: UIFont.systemFont(ofSize: 16, weight: .bold))
        
        override init(frame: CGRect) {
            super.init(frame: frame)
            setUI()
        }
        
        required init?(coder: NSCoder) {
            super.init(coder: coder)
            setUI()
        }
        
        func setUI() {
            addSubview(topTilte)
            addSubview(subTitle)
            
            topTilte.snp.makeConstraints { make in
                make.top.equalToSuperview()
                make.left.equalToSuperview()
                make.right.greaterThanOrEqualTo(self)
            }
            
            subTitle.snp.makeConstraints { make in
                make.top.equalTo(topTilte.snp.bottom).offset(2)
                make.left.equalToSuperview()
                make.bottom.equalToSuperview()
                make.right.greaterThanOrEqualTo(self)
            }
            
        }
        
    }
}
